# Maintainer: Junjie Mao <eternal.n08@gmail.com>

_realname=ocaml-camlp4
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.02.1
patchver=3
pkgrel=6
pkgdesc="Pre-Processor-Pretty-Printer for OCaml (mingw-w64)"
arch=('any')
url='https://github.com/ocaml/camlp4'
license=('LGPL2')
depends=("${MINGW_PACKAGE_PREFIX}-ocaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-flexdll")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/ocaml/camlp4/archive/${pkgver}+${patchver}.tar.gz"
        "0001-Properly-quote-preprocessor-command-to-ocamldep.patch"
        "0003-Guess-the-library-path-on-msys2.patch")
sha256sums=('c28058b20016dac51d492b1a98e6453d2c7097100542c99a0593cc240a3eeada'
            'cc5d6fe07d5bff025caa431b62b1e83154490459f75634062975786b5d691814'
            '08080dde32d4714bdf41349c597c1220468c609c15a81d4e75be828cded44fe2')

prepare() {
  cd ${srcdir}/camlp4-${pkgver}-${patchver}

  patch -p1 -i ${srcdir}/0001-Properly-quote-preprocessor-command-to-ocamldep.patch
  patch -p1 -i ${srcdir}/0003-Guess-the-library-path-on-msys2.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf camlp4-${pkgver}-${patchver} build-${MINGW_CHOST}

  cd ${srcdir}/build-${MINGW_CHOST}
  ./configure --bindir=${MINGW_PREFIX}/bin \
              --libdir=${MINGW_PREFIX}/lib/ocaml \
              --pkgdir=${MINGW_PREFIX}/lib/ocaml
  make all -j1
}

check() {
  # The package does not include an automatic test process
  plain "skip"
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install -j1
  make DESTDIR=${pkgdir} install-META -j1
  [ -f LICENSE ] && install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
